package com.zte.claa.inficombo.csa.app.service.jsplugin;

import java.util.HashMap;
import java.util.Map;

import com.zte.claa.inficombo.csa.app.service.persistent.CSADataPersistService;

public class JSParam {
	// js插件中上报数据解析的function名称，统一固定命名 。
	public static final String UPDATA_PARSE_FUNC = "funcupdataparse";
	// js插件中上报数据分包二次补偿解析的function名称，统一固定命名 ，入参是：MultiPackageData mpd
	public static final String UPDATA_MULTIPKG_REPARSE_FUNC = "funcmultipkgreparse";
	// 上报数据解析时，传入js的payload-paras参数
	public static final String UPDATA_PARA_NAME = "uppayload";
	// 上报数据涉及分包和组包时的分包中间结果 MultiPackageData的参数名.
	public static final String MULTIPKG_PARA_NAME = "multipkgdata";
	// 上报数据解析时，传入js的detail附加paras参数(json对象参数)
	public static final String DETAIL_PARA_NAME = "detail";
	
	private String devtypeid;
	private String deveui;
	private String devport;
	private String appeui;
	private String projectid;
	private String devname;
	// 传感器id，仅GSP/SSP设备需要，-1表示无效.
	private int sensorid = -1;
	private Map<String, Object> paras = new HashMap<String, Object>(); 
	// 针对自研设备的模型附加数据信息.
	private Map<String, Object> devExtDatas = new HashMap<String, Object>(); 
	
	// 持久化服务，仅在数据解析流程中会设置...
	private CSADataPersistService persistSvr = null;
	
	// 构建器.
	public JSParam(){
		
	}

	public String getDevtypeid() {
		return devtypeid;
	}

	public void setDevtypeid(String devtypeid) {
		this.devtypeid = devtypeid;
	}

	public String getDeveui() {
		return deveui;
	}

	public void setDeveui(String deveui) {
		this.deveui = deveui;
	}

	public String getDevport() {
		return devport;
	}

	public void setDevport(String devport) {
		this.devport = devport;
	}

	public String getAppeui() {
		return appeui;
	}

	public void setAppeui(String appeui) {
		this.appeui = appeui;
	}
	
	/**
	 * @return the projectid
	 */
	public String getProjectid() {
		return projectid;
	}

	/**
	 * @param projectid the projectid to set
	 */
	public void setProjectid(String projectid) {
		this.projectid = projectid;
	}

	public int getSensorid() {
		return sensorid;
	}

	public void setSensorid(int sensorid) {
		this.sensorid = sensorid;
	}

	public Map<String, Object> getParas() {
		return paras;
	}
	
	public Object getPara(String paraName){
		return this.paras.get(paraName);
	}

	public void setParas(Map<String, Object> paras) {
		this.paras = paras;
	}
	
	public void appendPara(String paraName, Object paraValue){
		if(this.paras == null){
			this.paras = new HashMap<String, Object>();
		}
		this.paras.put(paraName, paraValue);
	}

	public Map<String, Object> getDevExtDatas() {
		return devExtDatas;
	}
	
	public Object getDevExtData(String dataName){
		return this.devExtDatas.get(dataName);
	}

	public void setDevExtDatas(Map<String, Object> devExtDatas) {
		this.devExtDatas = devExtDatas;
	}

	public String getDevname() {
		return devname;
	}

	public void setDevname(String devname) {
		this.devname = devname;
	}

	public void appendDevExtData(String dataName, Object dataValue){
		if(this.devExtDatas == null){
			this.devExtDatas = new HashMap<String, Object>();
		}
		this.devExtDatas.put(dataName, dataValue);
	}

	public CSADataPersistService getPersistSvr() {
		return persistSvr;
	}

	public void setPersistSvr(CSADataPersistService persistSvr) {
		this.persistSvr = persistSvr;
	}	
	
	public Map<String, Object> getDevLatestMetedata(String devEui) {
		if(this.persistSvr == null){
			return null;
		}
		try{
			Map<String, Object> ret = this.persistSvr.queryDevLatestMeteDataAsMap(devEui);
			if(ret != null){
				return ret;
			}
		}catch(Exception ignore){}
		return null;
	}
}
